package com.cn.distributor.service.Impl;

//import api.ProductFeignClient;


import com.cn.api.ProductCoreService;
import com.cn.common.result.Result;
import com.cn.distributor.entity.Product;
import com.cn.distributor.mapper.ShopMapper;
import com.cn.distributor.service.ShopService;
import com.cn.distributor.vo.GoodsIdVo;
import com.cn.distributor.vo.ShopIdVo;
import com.cn.distributor.vo.ShopVo;
import com.cn.dto.ProductDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;
@FeignClient
@Service("/ShopService")

public class ShopServiceImpl implements ShopService {

    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private ProductCoreService productCoreService;

//    @Autowired
//    private ProductFeignClient productFeignClient;
  @Override
    public Result findByOrder(ShopIdVo shopIdVo) {
//        List<News> newsModelList = newsMapper.findAll(news);
//        return Result.success(pageInfo.getTotal(), newsModelList);---调用订单查询
        return null;
    }

    @Override
    public Result share(GoodsIdVo goodsIdVo) {
        return null;
    }

    @Override
    public Result modifyStore(ShopVo shop, ShopIdVo shopIdVo) {
      long count = shopMapper.modifyStore(shop,shopIdVo);
        return Result.success(count);
    }

    @Override
    public Result deleteGoods(GoodsIdVo goodsIdVo, ShopIdVo shopIdVo) {

      long count = shopMapper.deleteGoods(goodsIdVo,shopIdVo);

        return Result.success(count);
    }

    @Override
    public Result addGoods(GoodsIdVo goodsIdVo, ShopIdVo shopIdVo) {
      long count = shopMapper.addGoods(goodsIdVo,shopIdVo);
        return Result.success(count);
    }


    @Override
    public Result goods(GoodsIdVo goodsIdVo, ShopIdVo shopIdVo) {
        long count = shopMapper.goods();
        return Result.success(count);
    }

    @Override
    public List allProduce(ShopIdVo shopIdVo) {

       List <Product> products = shopMapper.findById(shopIdVo);

         List<ProductDTO> productDTOS = new ArrayList<>();
        for (int i = 0; i <products.size() ; i++) {
            productDTOS.add(productCoreService.findById(products.get(i).getProductId()))  ;
        }
        return productDTOS;
    }
}
